<?php
    session_start();
    include('conn.php');
    include('protect.php');
	include('gettopmenu.php');
   	error_reporting(0);

	$dt=date("d-m-Y");
    $dt1=date("d-m-Y");
	$msg='';
	
	
	if(!isset($_REQUEST['flag']))
{
$show=1;
}     

else if($_REQUEST['flag']==1)
{   
$show=2;
$tranid=$_REQUEST['tranid'];

} // flag==1	

else if($_REQUEST['flag']==2)
{   
$show=2;
$tranid=$_REQUEST['tranid'];


		$bankdate=$_REQUEST['datepicker3'];
		$pnr=$_REQUEST['pnr'];
		$sector=$_REQUEST['sector'];
		$tax=$_REQUEST['tax'];
		$travelDate=$_REQUEST['paydate'];
        $returnDate=$_REQUEST['returndate'];
		$basic=$_REQUEST['basic'];
		$admamt=$_REQUEST['admamt'];
		$idnumber=$_REQUEST['idnumber'];
		$ticket=$_REQUEST['ticket'];
		$pax=$_REQUEST['pax'];
		//$amount=$_REQUEST['amount'];
	
	$amount=$tax+$admamt+$basic;
$bd=explode("-", $bankdate);  //format date-month-year will the format year-month-date
$bankdate=$bd[2].'-'.$bd[1].'-'.$bd[0];

$td=explode("-", $travelDate);  //format date-month-year will the format year-month-date
$travelDate=$td[2].'-'.$td[1].'-'.$td[0];


$rd=explode("-", $returnDate);  //format date-month-year will the format year-month-date
if(count($rd) == 3)
	$returnDate=$rd[2].'-'.$rd[1].'-'.$rd[0];
else
	$returnDate='NULL';

	
	$inv='';
	$enter='';
	if(($pnr!='') AND ($sector!=''))
	{ // if(($pnr!='') AND ($sector!='') AND ($idnumber!='')) [starts]

/*
$sql="insert into transactiondetails(tranid,`Bkng Date`,`ID Number`,`Pax Name`, `Ticket Number`,PNR, 
Sector,`Travel Date`,Basic,Tax,Admincharges,Amount,invoicenumber_notnused,entereddate_notused)
			values('".$tranid."','".$bankdate."','".$idnumber."','".$pax."','".$ticket."','".$pnr."','".$sector."','".$travelDate."','".$basic."','".$tax."','".$admamt."','".$amount."','".$inv."','".$enter."')";
	*/
			
$sql="insert into transactiondetails(
select null,'$tranid','$bankdate','$idnumber','$pax','$ticket','$pnr','$sector','$travelDate',case when length($returnDate) > 0 then '$returnDate' else NULL end,'$basic','$tax','$admamt','$amount','$inv',''

)";
			
		
$insertQ=mysql_query($sql);


			if($insertQ)
		{
		
 $QTransDetailsSumAmt=mysql_fetch_array(mysql_query("select sum(Amount) SumAmount from transactiondetails where tranid='$tranid'   "));
 $QTransDetailsSumAmt_var = $QTransDetailsSumAmt['SumAmount'];

 
//update transactionmast set creditamt = case when bid = 15 then  4567 else creditamt end where trnid=5202
 $qUpdateTmast=mysql_query(" update transactionmast set creditamt = case when bid = 15 then '$QTransDetailsSumAmt_var' else creditamt end  where trnid='$tranid' ");
  $qUpdateTmast=mysql_query(" update transactionmast set debitamt = case when bid != 15 then '$QTransDetailsSumAmt_var' else debitamt end  where trnid='$tranid' ");
 
		?>	
        <script>window.location.href = 'TransactionDetails.php?flag=1&tranid=<?php echo $tranid; ?>'</script>
        <?php 	
		
		}
	
	}// if(($pnr!='') AND ($sector!='') AND ($idnumber!='')) [starts]
	
	else
	{ 
	
	
	?>
	 <script>window.location.href = 'TransactionDetails.php?flag=1&tranid=<?php echo $tranid; ?>'</script>
	<?php
	
	}
	
} // flag==2	



?>

 <style type="text/css">
<!--
.head {
	font-size: 18px;
	font-weight: bold;
	font-style: italic;
	color: #666666;
}
-->
      </style>

<style type="text/css">
.textst{ color:#666666; font-family: Arial, Helvetica, sans-serif; font-size:14px; font-weight:700}
</style>
 <script type="text/javascript" src="main.js"></script>
 
 <!--Added by jack for auto calculation-->
<!-- <script type="text/javascript" src="scrpts/jquery.validate.js"></script>
<script type="text/javascript" src="scrpts/jquery-1.8.0.min.js"></script> !-->

<!--Added by jack for auto calculation-->
  
  
  
 <script language="javascript">
       $(function() {
               $("#datepicker3").datepicker({ dateFormat: "dd-mm-yy" }).val();
			   $("#datepicker4").datepicker({ dateFormat: "dd-mm-yy" }).val();
               $("#paydate").datepicker({ dateFormat: "dd-mm-yy" }).val();	
               $("#returndate").datepicker({ dateFormat: "dd-mm-yy" }).val();	   
       });
	  function chkamt()
	  {
	  	document.frmtran.balamount.value=document.frmtran.dramount.value-document.frmtran.cramount.value;
	  } 
	
 //   function chkpay()
  //    {
//		if (document.frmtran.payid.value==2)
//		{
//			document.getElementById('bankid').disabled = false;
//			document.getElementById('branch').disabled = false;
//		}
//		else
//		{
//			document.getElementById('bankid').disabled = true;
//			document.getElementById('branch').disabled = true;
//		}
//	  }

    function chkdramt()
      {
    	if (document.frmtran.dramount.value>0)
		{
			document.getElementById('bankid').disabled = true;
			document.getElementById('branch').disabled = true;
            document.getElementById('paydate').disabled = true;
            document.getElementById('payid').disabled = true;
		}
		else
		{
			document.getElementById('bankid').disabled = false;
			document.getElementById('branch').disabled = false;
            document.getElementById('paydate').disabled = false;
            document.getElementById('payid').disabled = false;
		}
	  }

 function chkcramt()
      {
        if (document.frmtran.cramount.value>0)
		{
			document.getElementById('bankid').disabled = false;
          	document.getElementById('branch').disabled = false;
            document.getElementById('paydate').disabled = false;
            document.getElementById('payid').disabled = false;
		}
		else
		{
			document.getElementById('bankid').disabled = true;
			document.getElementById('branch').disabled = true;
            document.getElementById('paydate').disabled = true;
            document.getElementById('payid').disabled = true;
		}
	  }


	  function validatefrm()
	  {
		if (document.frmtran.payid.value==2)
		{
			if (document.frmtran.bankid.value==1)
			{
				alert("select Bank name");
				document.frmtran.bankid.focus();
				return false;
			}	
			if (document.frmtran.paydate.value=="")
			{
				alert("select Pay Date");
				document.frmtran.paydate.focus();
				return false;
			}	
			if (document.frmtran.branch.value=="")
			{
				alert("Enter Branch Name");
				document.frmtran.branch.focus();
				return false;
			}	
		}	
	  }
	function chgd()
	{
	  	//alert(document.frmtran.custid.value);
		var a=document.frmtran.custid.value;
		if(a.substring(0,1)=="i")
		{
			document.frmtran.sid.disabled = false;
		}
		else
		{
			document.frmtran.sid.disabled = true;
		}
		if(a.substring(0,1)=="c")
		{
			document.getElementById('ct').innerHTML="Customer";
		}
		if(a.substring(0,1)=="i")
		{
			document.getElementById('ct').innerHTML="Distributor";
		}
		if(a.substring(0,1)=="d")
		{
			document.getElementById('ct').innerHTML="Agent";
		}
	}  
 </script>
 
 
<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Transaction / Add Transaction</label></td>
<div  align="center">
	<div  ng-controller="MyCtrl">
	<div align="center">
	
	<?php
	  $Qinv=mysql_fetch_array(mysql_query(" select invoicenumber from transactionmast where trnid='$tranid' "));
	  
	$qry1 = "SELECT A.trnid,A.trndate,A.invoicenumber TinvoiceNum,B.bdesc,C.catdesc ,D.custdesc,D.appadmchrg ,D.custtype,E.subname,A.debitamt,A.creditamt,F.bankname,A.branchname,A.remarks,A.paydate,A.enteredby,G.pdesc
FROM transactionmast A, businessmast B,categorymast C, customermast D, subdealermast E, bankmast F, paymentmast G
where A.bid=B.bid and A.catid=C.catid and A.custid=D.custid and A.subid=E.subid and A.bankid=F.bankid and A.payid=G.payid and A.trnid ='".$tranid."'";// order by A.trnid desc";


$r1=mysql_fetch_array(mysql_query($qry1)); 
$invoiceNumber=$r1['TinvoiceNum'];
$admincharges = 0;
$admincharges = $r1['appadmchrg'];
?>


	<table width="874" bgcolor="#E0EBED" style="padding:10px; text-align:center">
	<tr bgcolor="#f5f5f5"><td ><br>
	<span class="head" >Details Of Master Transaction NO  &nbsp; &nbsp; <?php echo $tranid; ?> [CLIENT: <font color="#660000"><?php echo $r1['custdesc']; ?></font>] [Admin Charge: <font color="#660000"><?php echo number_format((float)$admincharges, 2, '.', ''); ?></font>]  </span></td>
	</tr>
	
	
	<tr bgcolor="#E0EBED"><td>
	<table width="1254" border="0" class="des" >
  <tr>
 
    <td width="102" bgcolor="EBE9E9"><span class="style4"><strong>Type</strong></span></td>
   
    <td width="113" bgcolor="EBE9E9"><span class="style4"><strong>Business</strong></span></td>
    <td width="82" bgcolor="EBE9E9"><strong>Category</strong></td>
    <td width="135" bgcolor="EBE9E9"><span class="style4"><strong>Sub-Agent Name </strong></span></td>
	
    <td width="63" bgcolor="EBE9E9"><span class="style4"><strong>Debit</strong></span></td>
    <td width="64" bgcolor="EBE9E9"><span class="style4"><strong>Credit</strong></span></td>
    <td width="125" bgcolor="EBE9E9"><strong>Bank</strong></td>
    <td width="131" bgcolor="EBE9E9"><strong>Branch</strong></td>
    <td width="134" bgcolor="EBE9E9"><strong>Pay date</strong></td>
    <td width="134" bgcolor="EBE9E9"><strong>Payment Method </strong></td>
    <td width="158" bgcolor="EBE9E9"><strong>Remarks</strong></td>
    <td width="36" bgcolor="EBE9E9"><strong> QTY </strong></td>
    
    <td width="26" bgcolor="EBE9E9">&nbsp;</td>
    <td width="31" bgcolor="EBE9E9">&nbsp;</td>
    </tr>

  <?php 
 
 
 
 $DC=mysql_fetch_array(mysql_query(" select count(tranid) as c from transactiondetails where tranid='$tranid' ")); 
 $color='#F9F8F8';

  ?>
 
  <tr bgcolor="<?php echo $color; ?>">
   
	
    <td style="border-right:  solid 1px #CCCCCC"><?php echo "$r1[custtype]"?></td>
    <td  style="border-right:  solid 1px #CCCCCC"><?php echo "$r1[bdesc]"?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo "$r1[catdesc]"?></td>
 
    <td style="border-right:  solid 1px #CCCCCC" ><?php echo $r1['subname']; ?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $r1['debitamt']?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $r1['creditamt'] ?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $r1['bankname'] ?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $r1['branchname'] ?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $r1['paydate'] ?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $r1['pdesc'] ?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $r1['remarks'] ?></td>
    <td style="border-right:  solid 1px #CCCCCC"><?php echo $DC['c'] ?></td>
    <td style="border-right:  solid 1px #CCCCCC">
	<?php 
 if(($invoiceNumber==0) OR ($invoiceNumber=='')) { 
	 if(($r1['bdesc']=="AIR TICKET") or ($r1['bdesc']=="CREDIT NOTE")) { ?>
	<form method="post" action="TransactionDetails.php">
	<input name="submit" type="image" src="images/detail.png" />
	<input name="flag" type="hidden" value="<?php echo 1;?>" />
	<input name="tranid" type="hidden" value="<?php echo $tranid;?>" />

	</form>	
	<?php  }} ?>
	</td>
    <td style="border-right:  solid 1px #CCCCCC">
	<?php  if( ($r1['bdesc']=="AIR TICKET") or ($r1['bdesc']=="CREDIT NOTE")) { ?>
	<?php if($DC['c']>0) {?>
	<form method="post" action="ViewTransactionDetails.php">
<input name="submit" type="image" src="images/view.png"/>
	
	<input name="tranid" type="hidden" value="<?php echo $tranid;?>" />
	</form>
	<?php  } ?>	
	<?php  } ?>
	</td>
    </tr>
</table>
</td></tr>
<tr bgcolor="#f5f5f5">
  <td bgcolor="#fff"><a href="viewgriddata.php">View  Master Transaction </a></td>
</tr>

</table>
<br>
	
	<?php if($show==2) {
	
	 $QT=mysql_fetch_array(mysql_query("select * from transactionmast where trnid='$tranid' ")); 
	 
	  if(($invoiceNumber==0) OR ($invoiceNumber=='')) { 
      if(($r1['bdesc']=="AIR TICKET") or ($r1['bdesc']=="CREDIT NOTE")) { 
 
	
	?><FORM METHOD="post" name="frmtran" action="TransactionDetails.php" onsubmit="return validatefrm();">
			<table  cellpadding="4" id="box-table-a" cellspacing="4" border="1" width="874" bgcolor="#000000" style="background-color:#DFEBF9;">
				<tr><td colspan="6" align="center" height="30" style="text-align:center; color:#FF0000;"><?=$msg?></td></tr>
				<tr>
				  <td colspan="6" align="center" height="30" style="text-align:center;font-size:14px; color:#333333; font-weight:bold; ">Transaction Details Entry against Master Transaction NO  <?php echo $tranid; ?></td>
				</tr>
				<tr bgcolor="#FFFFFF">
				  <td width="149"><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Booking Date  </label></td>
				  <td width="9"><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="272" style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= ""  id="datepicker3" name="datepicker3" class="smallInput" />				  </td>
				<td width="99" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">ID Number </label></td>
				  <td width="5" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="250"  style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= ""  id="idnumber" name="idnumber" value="<?php echo $QT['IDNumber'];?>" disabled="disabled" class="smallInput" />				  </td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Pax Name</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= ""  id="pax" name="pax" class="smallInput" />					</td>
				  <td width="99" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Ticket Number</label></td>
				  <td width="5" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="250"  style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= ""  id="ticket" name="ticket" class="smallInput" />				  </td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">PNR</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<p>
						  <input type="text" required= ""  id="pnr" name="pnr" class="smallInput" />
					  </p>
					<p>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;"> SECTOR </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= ""  id="sector" name="sector" class="smallInput" />					</td>
				</tr>
				
				
				<tr bgcolor="#fff">
				<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Travel Date</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= ""  id="paydate" name="paydate" class="smallInput" />					</td>
                        <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Return Date</label></td>
    				<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text"  id="returndate" name="returndate" class="smallInput" />					</td>
                        </tr>
            
				 
				<tr bgcolor="#FFFFFF">
                 <td width="99" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Basic</label></td>
    			  <td width="5" ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td width="250"  style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" required= ""  id="basic" name="basic" class="smallInput" value="0" />				  </td>
				
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Tax</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<p>
						  <input type="text" required= ""  id="tax" name="tax" class="smallInput"  value="0"/>
					  </p>
					<p>
				</tr>
				
				
				<tr bgcolor="#FFFFFF">
                    <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;"> Admin Charges </label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					<input type="text" required= ""  id="admamt" name="admamt" class="smallInput"  value="0" />			</td>
				                    
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Amount</label></td>
					<td><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<p>
				  	  <div id="admincharcges"><input type="text"   id="amount" name="amount" class="smallInput"  disabled="disabled" value="0"  /></div>	
					  </p>
					<p>
                    </td>
					</tr>
						
				<tr>
					<td align="center" colspan="6" style="background-color:#BBE2EE">
						<input type="submit"  name="submit" value="Save Record" />	
						<input type="hidden"  name="flag" value="<?php echo 2;?>" />	
						<input type="hidden"  name="tranid" value="<?php echo $tranid;?>" />
						<input type="hidden" name="idnumber" value="<?php echo $QT['IDNumber'];?>" />			
				  </td>
				</tr>
			</table>
			</FORM>
			
			<?php }  } } ?>
	
	</div>

<!--		OR
		</br>
		<strong>Reference No:</strong> </string>
		<input type="text" ng-model="Referenceno"/>	</br>      
		<button ng-click="activateFilter()"> Search </button>   <br/>
			<br/>
-->
</div>
</div>
</body>
</html>


<script type="text/javascript">

	$("#basic,#tax,#admamt").keyup(function(){
		$.ajax({
			type: "GET",
			url: "adminch.php",
			data: "basic="+$("#basic").val()+"&tax="+$("#tax").val()+"&admamt="+$("#admamt").val(),
			success:function(result){				
    			$("div#admincharcges").html(result);
			}	
		
		});
	});
	

	</script>




